<?php	

class actions extends Controller
{
	
	public function add()
	{	
		$this->session();
		$orgs = new organization();
		$orgs->insertOrg($_POST['Name'], $_POST['Desc'], '', ''); 
		$message = 'Add successful. Click <a href="/admin/orgs/add">here</a> to go back.' ;
		new View('emptyTemplate', 
		array( 'message' => $message )) ;	
	}

	public function edit()
	{	
		$this->session();
		$orgs = new organization();
		$orgs->updateOrg($_POST['Name'], $_POST['Desc'], '', '', $_POST['orgId']); 
		$message = 'Edit successful. 
		Click <a href="/admin/orgs">here</a> to go back.' ;
		new View('emptyTemplate', array( 'message' => $message )) ;
	}

	public function del() {
		$this->session();
		// pag confirm na
		if( func_num_args() > 0 ) {
			if( func_get_arg(0) == 'confirm' ) {
				if( isset( $_POST['yes'] ) ) {
					$org = new organization();
					$org->deleteOrgs( $_POST['orgids'] );
					$message = 'Organization(s) has/have been deleted. Click <a href="/admin/orgs">here</a> to go back to ';
					new View('emptyTemplate', 
						array( 'message' => $message ) 
					);
				}
				if( isset( $_POST['no'] ) ) {
					header('Location: /admin/orgs'); // url na babalikan pag pinindot ang no
				}
			}
		}
		
		// pag wala pang confirm
		else {
			$hiddenVars['orgids'] = $_POST['orgids'];
			$confirmVars['url'] = '/orgs/actions/del/confirm'; 
			$confirmVars['message'] = 'Are you sure you want to delete this/these orgs?';
			$confirmVars['hiddenVars'] = $hiddenVars;
			$confirmForm = new BufferedView('confirmForm', $confirmVars);
			
			new View(
				'siteadmin/template',
				array(
					'title' => new BufferedView('tConfirmForm'),
					'content' => $confirmForm
				)
			);
		}
		
	}
}

